import { reactive, computed } from "vue";
import Api from "@/utils/http";

type TList1 = Array<{
  user_id: string;
  avatar: string;
  username: string;
  num: number;
}>;
const state = reactive({
  user_id: "",
  max_machine_num: 724,
  machine_num: 0,
  task_num: 10,
  quantity: 0,

  tabIndex: 1,
  list1: [] as TList1,
  list2: [] as TList1,
  list3: [] as Array<{
    user_id: string;
    avatar: string;
    username: string;
    amount: string;
  }>,

  modalOne: false,
  modalShare: {
    show: false,
    quantity_count: 0,
    result: [] as Array<{
      user_id: string;
      avatar: string;
    }>,
  },
  enterQuota: 1,
  modalTaskadd: false,
  modalTaskok: false,
  modalTaskno: false,
  modalTaskEnd: true,
});
export const maxEnterQuota = computed(() => {
  return Math.min(state.task_num, state.quantity, 10);
});
export const getConfig = async () => {
  const res = await Api.get("queen/config_info", {
    loading: false,
    returnCode: true,
  });
  if (res.code === "0") Object.assign(state, res.data);
};
export const getList = async () => {
  const res: any = await Promise.all([
    Api.get("queen/leader_board?list_type=1", { returnCode: true }),
    Api.get("queen/leader_board?list_type=2", { returnCode: true }),
    Api.get("queen/leader_board?list_type=3", { returnCode: true }),
  ]);
  [state.list1, state.list2, state.list3] = res.map(
    (item: any) => item.data || []
  );
};

export default state;
